package com.clouddisk.file.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.clouddisk.file.entity.File;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface FileMapper extends BaseMapper<File> {

    @Select("SELECT COALESCE(SUM(file_size), 0) FROM file WHERE user_id = #{userId} AND status = 0")
    Long getUserStorageUsed(@Param("userId") Long userId);

    @Select("SELECT COUNT(*) FROM file WHERE user_id = #{userId} AND parent_id = #{parentId} AND file_name = #{fileName} AND status = 0")
    Integer checkFileNameExists(@Param("userId") Long userId, @Param("parentId") Long parentId, @Param("fileName") String fileName);
} 